<?php


namespace app\common\model;


use think\Model;

class AccountLog extends Model
{
    protected $pk = "log_id";
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    //修改format类型
    protected $dateFormat = "Y-m-d H:i:s";
    protected $type = [
        'money'     => 'float'
    ];
    public function getPkAttr($value,$data) {
        return $this->pk;
    }
    public function user(){
        return $this->hasOne(Users::class, 'user_id','user_id');
    }
    public function guser(){
        return $this->hasOne(Users::class, 'user_id','gid');
    }
    public function dingdan(){
        return $this->hasOne(Order::class, 'order_id','order_id');
    }
    public function getTypeTextAttr($value,$data) {
        $types = [1=>'粮票',2=>'积分',3=>'牧场补贴',4=>'储备金'];
        return $types[$data['type']];
    }
    public function getTimeAttr($value,$data) {
        return $data['add_time'];
    }
    public function getTimeTextAttr($value,$data) {
        return date('Y-m-d H:i',$data['add_time']);
    }
}
